Skip to content

fix: Basis.image_2d_from and dPIEPotential.convergence_2d_from return wrong wrapper types#425

Merged
Jammy2211 merged 1 commit into
mainfrom
feature/profile-return-type-fixes
May 18, 2026
Merged

fix: Basis.image_2d_from and dPIEPotential.convergence_2d_from return wrong wrapper types#425
Jammy2211 merged 1 commit into
mainfrom
feature/profile-return-type-fixes

Conversation

@Jammy2211
Copy link
Copy Markdown
Collaborator

Summary

Two profile-return-type bugs surfaced while writing the new
autolens_workspace/scripts/guides/profiles/{light,mass}.py guides (#86 / #176 / #178 /
#179). Both forced workarounds in the workspace guides; both are tiny library-side fixes
that tighten the type contract advertised by the methods' annotations.

Closes #424.

API Changes

None — return-type fix only. Basis.image_2d_from and
dPIEPotential.convergence_2d_from already advertised aa.Array2D return types in their
annotations; this PR makes the runtime behaviour match. Any caller that already relies on
the (incorrect) numpy.ndarray / VectorYX2D returns will see a tighter type — none in
the codebase or workspaces do, since both methods were unusable through
aplt.plot_array before this fix.
See full details below.

Test Plan

  • python -m pytest test_autogalaxy/ passes (full test suite as baseline)
  • New regression tests in test_basis.py and test_dual_pseudo_isothermal_potential.py pass
  • Sanity-check via the autolens_workspace guides:
    • aplt.plot_array(array=basis.image_2d_from(grid=grid)) now works for a basis of lp_linear constituents (no Galaxy wrap needed).
    • aplt.plot_array(array=mp.dPIEPotential(...).convergence_2d_from(grid=grid)) now works.
Full API Changes (for automation & release notes)

Fixed

  • autogalaxy.profiles.basis.Basis.image_2d_from — previously returned a raw numpy.ndarray when the basis contained only LightProfileLinear constituents (the MGE case); now returns aa.Array2D uniformly.
  • autogalaxy.profiles.mass.total.dual_pseudo_isothermal_potential.dPIEPotential.convergence_2d_from — previously returned aa.VectorYX2D (wrong wrapper from a copy-paste of the deflections decorator); now returns aa.Array2D matching the corresponding dPIEPotentialSph.convergence_2d_from already in the same file.

Added (tests only)

  • test_autogalaxy/profiles/test_basis.py::test__image_2d_from__returns_array2d_for_linear_only_basis — regression test for the Basis fix.
  • test_autogalaxy/profiles/mass/total/test_dual_pseudo_isothermal_potential.py::test__convergence_2d_from__returns_array2d_not_vector — regression test for the dPIEPotential fix.

Removed / Renamed / Changed Signature / Changed Behaviour / Migration

  • None — public API surface unchanged. Internal implementation now matches the documented return types.

🤖 Generated with Claude Code

Two profile-return-type bugs surfaced while writing the
autolens_workspace mass / light profile guides:

1. Basis.image_2d_list_from returned a raw xp.zeros((N,)) ndarray as
   the placeholder for LightProfileLinear constituents, so a basis
   composed entirely of linear profiles produced an
   image_2d_from = sum([ndarray, ndarray, ...]) that was itself a
   raw ndarray, contradicting the -> aa.Array2D return annotation.
   Wrap the placeholder in aa.Array2D so the return type is uniform.

2. dPIEPotential.convergence_2d_from was decorated with
   @aa.decorators.to_vector_yx (the deflections decorator directly
   above it) instead of @aa.decorators.to_array — the scalar
   convergence was being wrapped as a VectorYX2D. The Sph variant
   below already uses the correct decorator; this brings the
   elliptical variant in line.

Adds regression tests for both fixes asserting the correct wrapper
type. Closes #424.

🤖 Generated with [Claude Code](https://claude.com/claude-code)
@Jammy2211 Jammy2211 added the pending-release PR queued for the next release build label May 18, 2026
@Jammy2211 Jammy2211 merged commit a3a4eb1 into main May 18, 2026
6 checks passed
@Jammy2211 Jammy2211 deleted the feature/profile-return-type-fixes branch May 18, 2026 17:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pending-release PR queued for the next release build

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: Basis.image_2d_from and dPIEPotential.convergence_2d_from return wrong wrapper types

1 participant